package com.nikkerball.apps.darkhorse.model.core;

import com.nikkerball.apps.darkhorse.model.base.NameObject;
import com.nikkerball.apps.darkhorse.model.evaluation.subject.SubjectEvaluation;
import org.hibernate.annotations.Cascade;

import javax.persistence.*;
import java.util.List;

import static org.hibernate.annotations.CascadeType.*;

/**
 * Represents a Subject
 */
@Entity
@Table(name = "Subject")
public class Subject extends NameObject {

    // ----- instance fields -----

    private List<ClassYear> classYears;

    private List<SubjectEvaluation> subjectEvaluations;

    // ----- constructors -----

    public Subject() {
        super();
    }

    public Subject(String name) {
        super(name);
    }

    // ----- public methods -----

    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinTable(name = "ClassYear_Subject", joinColumns = @JoinColumn(name = "SubjectId"),
            inverseJoinColumns = @JoinColumn(name = "ClassYearId"))
    public List<ClassYear> getClassYears() {
        return this.classYears;
    }

    public void setClassYears(List<ClassYear> classYears) {
        this.classYears = classYears;
    }

    @OneToMany(mappedBy = "subject")
    @Cascade({MERGE, PERSIST, SAVE_UPDATE, DETACH, DELETE})
    public List<SubjectEvaluation> getSubjectEvaluations() {
        return this.subjectEvaluations;
    }

    public void setSubjectEvaluations(List<SubjectEvaluation> subjectEvaluations) {
        this.subjectEvaluations = subjectEvaluations;
    }
}
